/******************************************************************************
 *
 *               Microchip Memory Disk Drive File System
 *
 ******************************************************************************
 * FileName:        Demonstration.c
 * Dependencies:    FSIO.h
 * Processor:       PIC18
 * Compiler:        C18
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the �Company�) for its PICmicro� Microcontroller is intended and
 * supplied to you, the Company�s customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller products. The
 * software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN �AS IS� CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
*****************************************************************************/


/*****************************************************************************
	Note:  This file is included to give you a basic demonstration of how the
           functions in this library work.  Prototypes for these functions,
           along with more information about them, can be found in FSIO.h
*****************************************************************************/

//DOM-IGNORE-BEGIN
/********************************************************************
 Change History:
  Rev            Description
  ----           -----------------------
  1.2.4 - 1.2.6  No Change
  1.2.6          Add support for the PIC18F46J50_PIM
  1.3.4          Added support for PIC18F8722 on PIC18 Explorer Board
********************************************************************/
//DOM-IGNORE-END

#include <delays.h>
#include "FSIO.h"
    #pragma config FOSC = HSHP 		//HS oscillator (high power > 16 MHz)
	#pragma config WDTEN = OFF		//Watch dog timer is always disabled. SWDTEN has no effect. 
	#pragma config LVP = OFF		//Single-Supply ICSP disabled
	#pragma config MCLRE = EXTMCLR

char sendBuffer[80] = "100000000000000000000000000000000000000000000000000000000000000000000000000000E";
/*char send2[2] = "2";
char receiveBuffer[50];

char dirname1[16] = ".\\ONE\\TWO\\THREE";
char dirname2[14] = "ONE\\TWO\\THREE";
char dirname3[14] = "FOUR\\FIVE\\SIX";
char dirname4[60] = "FOUR\\FIVE\\SEVEN\\..\\EIGHT\\..\\..\\NINE\\TEN\\..\\ELEVEN\\..\\TWELVE";
char dirname5[31] = "\\ONE\\TWO\\THREE\\FOUR\\FIVE\\EIGHT";
char dirname6[10] = "FOUR\\NINE";
char dirname7[2];*/

void main (void)
{
	FSFILE * pointer;
	/*char path[30];
	char count = 30;
	char * pointer2;
	SearchRec rec;
	unsigned char attributes;
	unsigned char size = 0, i;*/
	int j = 0;
    TRISA &= 0xFE;
	LATAbits.LATA0 = 0;
	ADCON1 |= 0x0F;                 // Default all pins to digital
    while (!MDD_MediaDetect());		// Detect if the SDcard is plugged on the card
	// Initialize the library
	
	while (!FSInit());	

	pointer = FSfopenpgm ("DATA.TXT", "w");
		if (pointer == NULL)
			while(1);
		
	// Create a file
	for(j=0;j<255;j++){
		LATAbits.LATA0 = 1;
		
		// Write 21 1-byte objects from sendBuffer into the file
		if (FSfwrite ((void *)sendBuffer, 1, 80, pointer) != 80)
				while(1);
	
		// FSftell returns the file's current position
		/*if (FSftell (pointer) != 21)
			while(1);*/
	
		// FSfseek sets the position one byte before the end
		// It can also set the position of a file forward from the
		// beginning or forward from the current position
		/*if (FSfseek(pointer, 1, SEEK_END))
			while(1);
	
		// Write a 2 at the end of the string
		if (FSfwrite ((void*)send2, 1, 1, pointer) != 1)
			while(1);*/
	
		// Close the file
		
		if (FSfflushData(pointer))while(1);
		
		LATAbits.LATA0 = 0;
		Delay10KTCYx(200);
	
	}
	if (FSfclose (pointer))
			while(1);
	
	while(1);
}